﻿#ifndef WEBSOCKETSERVER_H
#define WEBSOCKETSERVER_H

#include <QObject>
#include <QWebSocket>
#include <QWebSocketServer>
#include <QList>

class WebSocketServer : public QObject
{
    Q_OBJECT
public:
    explicit WebSocketServer(quint16 port,QObject *parent = nullptr);
    ~WebSocketServer();

private slots:
    void onNewConnection();  // 当有新的客户端连接时调用
    void processTextMessage(const QString &message);  // 处理收到的文本消息
    void socketDisconnected();  // 客户端断开连接时调用

private:
    QWebSocketServer *m_webSocketServer;  // WebSocket 服务器对象
    QList<QWebSocket *> m_clients;  // 保存所有已连接的客户端

};

#endif // WEBSOCKETSERVER_H
